package org.divineryang.exception;

import org.divineryang.model.vo.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program new-bee
 * @Description 全局异常处理器
 * @Author Diviner Yang
 * @Date 2024/04/19 9:19
 * @Version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.build(null , 500,"服务器内部异常") ;
    }

    @ExceptionHandler(value = NewBeeException.class)     // 处理自定义异常
    @ResponseBody
    public Result error(NewBeeException exception) {
        exception.printStackTrace();
        return Result.build(null , exception.getResultCodeEnum()) ;
    }
}
